package cn.myfirefly.moming.portal.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.myfirefly.moming.portal.dao.UserBackgroundDao;
import cn.myfirefly.moming.portal.entity.MMUserBackground;
import cn.myfirefly.core.model.Identity;

@Service
@Transactional
public class UserBackgroundService {

	@Autowired
	private UserBackgroundDao userBackgroundDao;
	
	public MMUserBackground getBackgroundPicByUserSn(Integer userSn) {
		return userBackgroundDao.getBackgroundPicByUserSn(userSn);
	}
	
	public int saveBackGroudPic(Identity identity, String picName) {
		MMUserBackground userBackground = userBackgroundDao.getBackgroundPicByUserSn(identity.getUserSn());
		if (userBackground == null) {
			userBackground = new MMUserBackground();
			userBackground.setUserSn(identity.getUserSn());
		}
		userBackground.setBackgroundUrl(picName);
		return userBackgroundDao.save(userBackground);
	}
}
